import store from '@/store';
import api from '@/api';
let inited = false;
// 缓存用户信息，避免刷新丢失
const InfoCache = {
    inited() {
        return inited;
    },
    async init(query: Recordable) {
        if (inited) {return true}
        else {
            if (Reflect.has(query, 'token')) {
                // oa跳转
                const { success, moule } = await api.userModel.parseOAToken();
                if (success) {
                    store.commit('user/SET_TOKEN', moule);
                }
            }
            const res = await Promise.all([store.dispatch('user/GetUserInfo'), store.dispatch('user/GetDicOptions')]);
            console.log(res);
            if (res.every((item) => item.success)) {
                inited = true;
                return true;
            } else {
                return false;
            }
        }
    },
    clear() {
        inited = false;
    }
};

export default InfoCache;
